package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 添加地址
     * @param addressBook
     */
    @Insert("insert into address_book (city_code,city_name,consignee,detail,district_code,district_name" +
            ",is_default,label,phone,province_code,province_name,sex,user_id)" +
            "values (#{cityCode},#{cityName},#{consignee},#{detail},#{districtCode},#{districtName},#{isDefault}," +
            "#{label},#{phone},#{provinceCode},#{provinceName},#{sex},#{userId})")
    void insert(AddressBook addressBook);

    /**
     * 查询当前登陆用户的所有地址信息
     * @param addressBook
     * @return
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 修改地址信息，根据id修改
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 根据id查询地址信息
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);

    /**
     * 根据id删除地址信息
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);

    /**
     * 根据用户id修改是否默认地址
     * @param addressBook
     */
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefault(AddressBook addressBook);
}
